package com.jackeysun.widget.adapter

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView

/**
 *   Created by sunxunchao on 2022/3/18.
 */
abstract class DataSource<T> : IData {

    val items = mutableListOf<T>()
    var adapter: SimpleAdapter<T>? = null


    fun load(): List<T> = emptyList()

    fun getItemCount() = try {
        items.size
    } catch (e: Exception) {
        0
    }


    abstract fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): SimpleViewHolder

    fun onBindViewHolder(
        holder: SimpleViewHolder,
        position: Int
    ) {
    }

    fun onBindViewHolder(
        holder: SimpleViewHolder,
        position: Int,
        payloads: MutableList<Any>
    ) {
    }

    fun onAttachedToRecyclerView(recyclerView: RecyclerView) {}
    fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {}
    fun onViewDetachedFromWindow(holder: SimpleViewHolder) {}
    fun onViewAttachedToWindow(holder: SimpleViewHolder) {}
    fun onViewRecycled(holder: SimpleViewHolder) {}
}